$(function(){
    loadProduct();
})

var pageNum = 0;
function loadProduct(){
    $.ajax({
        url:server_url + "/rest/staff/staffIndex.do",
        data:{userId:userid,pageNum:pageNum,ran:Math.random()},
        success:function(data){

            $("#more").remove();
            $("#sth").remove();
            if(data.data == null || data.data.length == 0){
                var more = '<div class="box_r" onclick="loadProduct();" id="more">' +
                    '<p style="text-align: center;margin-top: 19px;">没有更多了</p></div>'
                $("#prodList").append(more);
                return;
            }
            mapIfExist(function(pro){
                var html = '<div class="box_r" onclick="detail('+pro.id+')">\
                                <div class="display_block">\
                            <div class="det_box">\
                            <img src="'+pro.picturePath1+'" alt="" class="">\
                            <div class="">\
                            <div class="con_tit">\
                            <p>'+pro.productName+'</p>\
                            <span>¥'+pro.price+'/头</span>\
                            </div>\
                            <p class="con_normal">'+pro.specName+' <span class="color_green">'+getApproveStatus(pro.approveStatus)+'</span></p>\
                            <p class="con_normal">库存：'+pro.overPlusNum+'头</p>\
                            <p class="con_normal">货源地：'+pro.areaName+'</p>\
                            <p class="con_normal">编号：'+pro.id+'</p>\
                            <p class="con_other"><strong class="color_green">货主：'+pro.supplyName+'</strong><span>'+pro.addTime.substring(0,10)+'</span></p>\
                            </div>\
                            </div>\
                            </div>\
                            </div>';

                $("#prodList").append(html);
            },data.data);
            pageNum++;
            var more = '<div class="box_r" onclick="loadProduct();" id="more">' +
                '<p style="text-align: center;margin-top: 19px;">加载更多</p></div>'
            var sth = '<div class="box_r" id="sth">\
                                <div class="display_block">\
                            <div class="det_box">\
                            <div class="">\
                            <div class="con_tit">\
                            <p></p>\
                            <span></span>\
                            </div>\
                            <p class="con_normal"> <span class="color_green"></span></p>\
                            <p class="con_normal"></p>\
                            <p class="con_normal"></p>\
                            <p class="con_normal"></p>\
                            <p class="con_other"><strong class="color_green"></strong><span></span></p>\
                            </div>\
                            </div>\
                            </div>\
                            </div>';
            $("#prodList").append(more);
            $("#prodList").append(sth);
        }
    })
}

function getApproveStatus(status)
{
    if(status == '1'){
        return "审核中";
    }
    if(status == '2')
    {
        return "审核未通过";
    }
    if(status == '3')
    {
        return "审核通过";
    }
}
function detail(id){
    window.location.href ='/LianniuWeb/staff/productDetail.do?id='+id;
}